package team.com;

import org.anddev.andengine.engine.camera.BoundCamera;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

public class Player {

	Body _body;
	float _posX, _posY;
	TextureRegion _playerRegion;
	Sprite _playerSprite;	
	
	Player(float x, float y, BoundCamera camera, PhysicsWorld world, Scene scene){
				
		_posX = x;
		_posY = y;
		_playerRegion = ResourcesManager.getInstance()._playerRegion;
		_playerSprite = new Sprite(_posX, _posY, _playerRegion);
		createPhysics(camera, world);
		camera.setBounds(0, _posX, 0, _posY);
		scene.attachChild(_playerSprite);
	}

	private void createPhysics(final BoundCamera camera, PhysicsWorld world) {
		
		_body = PhysicsFactory.createBoxBody(world, _playerSprite, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(0, 0, 0));
		_body.setUserData(this);
		_body.setFixedRotation(true);
		world.registerPhysicsConnector(new PhysicsConnector(_playerSprite, _body, true, true));
//		{
//			@Override
//			public void onUpdate(float sec)
//			{
//				super.onUpdate(sec);
//				camera.onUpdate(sec);
//				_body.setLinearVelocity(3, _body.getLinearVelocity().y);
//			}
//		});
	}
	
	public void jump()
	{
		_body.setLinearVelocity(_body.getLinearVelocity().x, 11);
	}
	
	public void run()
	{
		_body.setLinearVelocity(3, _body.getLinearVelocity().y);
	}
}
